import numpy as np


def input_size(interpreter):
    """Returns input image size as (width, height) tuple."""
    _, height, width, _ = interpreter.get_input_details()[0]['shape']
    return width, height


def input_tensor(interpreter):
    """Returns input tensor view as numpy array of shape (height, width, 3)."""
    tensor_index = interpreter.get_input_details()[0]['index']
    return interpreter.tensor(tensor_index)()[0]


def output_tensor(interpreter, i):
    tensor = interpreter.tensor(interpreter.get_output_details()[i]['index'])()
    return list(np.squeeze(tensor))


def set_input(interpreter, image):
    tensor = input_tensor(interpreter)
    tensor.fill(0)
    tensor[:, :, :] = np.ascontiguousarray(image.copy())


def get_output(interpreter):
    y = output_tensor(interpreter, 0)
    return y
